<template>
  <div class="editdata">
    <div class="tops">
      <van-nav-bar
        :title="textd"
        @click-left="onClickLeft"
        right-text="保存"
        @click-right="onClickRight"
      >
        <template #left>
          <i class="iconfont iconbtn_nav_back"></i>
        </template>
      </van-nav-bar>
    </div>
    <div class="inputs">
      <van-cell-group>
        <van-field v-model="value"></van-field>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import { edit } from '../../../api/api'
export default {
  data () {
    return {
      value: '',
      textd: ''
    }
  },
  created () {
    this.textd = this.$route.params.value
  },
  methods: {
    // 点击保存时触发
    async onClickRight () {
      console.log('点击了保存')
      if (this.textd === '修改昵称') {
        // console.log(this.value)

        this.$store.state.userInfo.nickname = this.value
        // console.log(this.value)
        // console.log(this.$store.state.userInfo.nickname)
        const res = await edit({ nickname: this.value })
        console.log(res)
        this.$router.back()
        this.$toast.success('修改成功')
      } else if (this.textd === '修改个人简介') {
        this.$store.state.userInfo.intro = this.value
        await edit({ intro: this.value })
        this.$router.push('/editInfo')
        this.$toast.success('修改成功')
      } else if (this.textd === '修改职位') {
        this.$store.state.userInfo.position = this.value
        await edit({ position: this.value })
        this.$router.go(-1)
        this.$toast.success('修改成功')
      }
    },
    // 点击返回上一页
    onClickLeft () {
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="less" scoped>
.editdata {
  .tops {
    /deep/ .iconfont {
      font-size: 35px;
    }
    .content {
      margin-top: 30px;
      margin-left: 100px;
    }
  }
  .inputs {
    background-color: #f7f4f5;
    /deep/ .van-cell__value--alone {
      color: #323233;
      text-align: left;
      background: #f7f4f5;
      height: 46px;
      border-radius: 6px;
    }
  }
}
</style>
